import sys
from ui_window import Ui_MainWindow
from PyQt4.QtCore import *
from PyQt4.QtGui import *


class MyForm(QMainWindow):
    def __init__(self):
        QWidget.__init__(self, None)
        self.setupUi()
        self.scene = QGraphicsScene()
        self.graphicsView.setScene(self.scene)
        self.scene.setSceneRect(0, 0, 1200, 800)    
        p1 = self.clickev()
        p2 = self.abc()
        
        p = p1.shape()
        r = p1.scene().sceneRect()
        q = QPainterPath()
        q.addRect(r)
        print p.intersected(q).length()         
        
    def on_graphicsView_mouseDoubleClickEvent(self, event):
        print event
        
    def setupUi(self):
        self.setObjectName("MainWindow")
        self.resize(1200, 800)                   
        self.graphicsView = QGraphicsView(self)
        self.graphicsView.resize(1200, 800)           
            
        
    def clickev(self):                
#        self.scene.addPixmap(QPixmap('c:/inne/wide-wallpaper-1680x1050-003.jpg'))
        c = QColor(255, 0, 0)
        p = QPen(c)
        p.setWidth(2)           
        path = QPainterPath()
        path.moveTo(-10, -10)
        path.lineTo(-3, -10)
        path.lineTo(-100, -100)
        path = self.scene.addPath(path, p)
        path.setZValue(5)
        return path
        
    def abc(self):
        c = QColor(0, 255, 0)
        p = QPen(c)
        b = QBrush(c)
        p.setWidth(2)           
        path = QPainterPath()
        path.addRect(6, 6, 110, 110)
        path = self.scene.addPath(path, p, b)
        path.setZValue(1)
        return path

if __name__ == '__main__':    
    app = QApplication(sys.argv)
    myapp = MyForm()
    myapp.show()    
    app.exec_() 
